package com.lap.auth.adapter.driven.web.menu;

import com.lap.auth.application.menu.MenuAppService;
import com.lap.auth.application.menu.command.CreateMenuCmd;
import com.lap.auth.application.menu.command.UpdateMenuCmd;
import com.lap.auth.application.menu.dto.MenuNodeDto;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "菜单管理", description = "提供菜单基本操作")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/menus")
public class MenuController {

  private final MenuAppService menuAppService;

  @Operation(summary = "获取菜单树")
  @GetMapping
  public List<MenuNodeDto> getMenuTree() {
    return menuAppService.queryMenuTree();
  }

  @Operation(summary = "添加菜单")
  @RepeatSubmit
  @PostMapping
  public Integer createMenu(@RequestBody @Valid CreateMenuCmd cmd) {
    return menuAppService.createMenu(cmd);
  }

  @Operation(summary = "更新菜单")
  @RepeatSubmit
  @PutMapping("{id}")
  public void updateMenu(@PathVariable Integer id, @RequestBody @Valid UpdateMenuCmd cmd) {
    menuAppService.updateMenu(id, cmd);
  }

  @Operation(summary = "删除菜单")
  @RepeatSubmit
  @DeleteMapping("{id}")
  public void deleteMenu(@PathVariable Integer id) {
    menuAppService.deleteMenu(id);
  }
}
